package com.itheima.tlias.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import java.io.IOException;

//@WebFilter(urlPatterns = "/*")
public class DemoFilter implements Filter {

    @Override //初始化方法，只调用一次
    public void init(FilterConfig filterConfig) throws ServletException {

        Filter.super.init(filterConfig);
        System.out.println("初始化方法，只调用一次");
    }

    @Override//每次拦截都调用一次，会调用多次
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("拦截到了请求");
        System.out.println("放行前的逻辑");
        //放行操作,非常重要的操作
        filterChain.doFilter(servletRequest,servletResponse);
        System.out.println("放行后的逻辑");
    }

    @Override //销毁方法，只调用一次
    public void destroy() {
        Filter.super.destroy();
        System.out.println("销毁方法");
    }
}
